package com.click369.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.click369.crm.mapper.CDeptMapper;
import com.click369.crm.pojo.CDept;
import com.click369.crm.service.DeptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class DeptServiceImpl implements DeptService{
	
	@Autowired
	private CDeptMapper deptMapper;
	//添加
	@Override
	public void save(CDept dept) {
		dept.setCreateTime(new Date());
		deptMapper.insert(dept);
	}
	//根据id删除
	@Override
	public void delete(Integer id) {
		deptMapper.deleteByPrimaryKey(id);
	}
	//修改
	@Override
	public void update(CDept dept) {
		dept.setUpdateTime(new Date());
		deptMapper.updateByPrimaryKey(dept);
	}
	//查询所有分页
	@Override
	public PageInfo<CDept> select(Integer page, Integer rows, CDept dept) {
		//分页
		PageHelper.startPage(page,rows);
		List<CDept> list = deptMapper.select(dept);
		return new PageInfo(list);
	}
	//根据id查询
	@Override
	public CDept getById(Integer id) {
		return deptMapper.selectByPrimaryKey(id);
	}
}
